package com.geek.bams.dao;

import com.geek.bams.entity.Account;

import java.util.ArrayList;
import java.util.List;

/**
 * @Desc 基于集合操作的CRUD
 * @Author chenmin
 * @Date 2025/10/13
 */
public class ListDao implements IDao<Account , List<Account>>{

    //容器
    private List<Account> accs = new ArrayList<>();

    //初始ID
    private Long id = 100000000000000000L;

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public boolean insert(Account account) {
        accs.add(account);
        return true;
    }

    @Override
    public Account selectOne(Long id, String password) {
        for (Account acc : accs) {
            if(acc!=null && id.equals(acc.getId()) && password.equals(acc.getPassword())){
                return acc;
            }
        }
        return null;
    }

    @Override
    public Account selectOne(Long id) {
        for (Account acc : accs) {
            if(acc!=null && id.equals(acc.getId())){
                return acc;
            }
        }
        return null;
    }

    @Override
    public List<Account> selectAll() {
        return accs;
    }
}
